/*
 * socketClient.cpp
 *
 *  Created on: 12.06.2009
 *      Author: Christian Stupp
 */

#include "../include/socketClient.h"

/**
 * Creates an client an connect it to the host
 */
oal::socketClient::socketClient(const std::string& host, int port) : socketObject() {
  std::string error;

  hostent *he;
  if ((he = gethostbyname(host.c_str())) == 0) {
#ifdef _WIN32
	error = strerror(errno);
#endif
    throw error;
  }

  sockaddr_in addr;
  addr.sin_family = AF_INET;
  addr.sin_port = htons(port);
  addr.sin_addr = *((in_addr *)he->h_addr);
  memset(&(addr.sin_zero), 0, 8);

  if (::connect(s_, (sockaddr *) &addr, sizeof(sockaddr))) {
#ifdef _WIN32
    error = strerror(WSAGetLastError());
#endif
    throw error;
  }
}

oal::socketClient::~socketClient() {
	// TODO Auto-generated destructor stub
}
